`
https://leetcode.cn/problems/rotate-image/
`

/**
 * @param {number[][]} matrix
 * @return {void} Do not return anything, modify matrix in-place instead.
 */
var rotate = function (matrix) {
  const n = matrix.length

  if (n === 1) return matrix

  // 将矩阵沿左上到右下的对角线进行翻转
  for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
      // 交换元素
      [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]
    }
  }

  // 水平翻转矩阵
  matrix.forEach(l => l.reverse())
};